$(() => {
  let $upnameText = $("#upnameText");
  let $btnOk = $("#btnOk");
  let $btnClear = $("#btnClear");
  let $btnToken = $("#btnToken");
  let $btnTest = $("#btnTest");
  let $content = $("#content");

  let isReq = false;

  $btnClear.on("click", () => {
    if (isReq) {
      return;
    }
    $upnameText.val("");
    $content.html("");
  });

  $btnOk.on("click", () => {
    if (isReq) {
      return;
    }
    isReq = true;
    let upname = $upnameText.val();
    $.post("/twTimeline", { upname }, (res) => {
      let { urls } = res;
      if (urls) {
        urls.forEach((n) => {
          $content.append(`<div>${n}</div>`);
        });
      } else {
        $content.append(`<div>查询失败,可能该up主账号不正确</div>`);
      }
      isReq = false;
    });
  });

  $btnToken.on("click", () => {
    $.post("/token", (data) => {
      console.log(data);
    });
  });

  $btnTest.on("click", () => {
    $.get("/test", (data) => {
      console.log(data);
    });
  });
});
